package com.ruoyi.front.controller;

import com.ruoyi.admin.domain.ZhxSubscribe;
import com.ruoyi.admin.domain.vo.ZhxSubscribeInfoAndTotal;
import com.ruoyi.admin.domain.vo.ZhxSubscribeListAndTotal;
import com.ruoyi.admin.service.IZhxSubscribeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户订阅Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/public/ZhxSubscribe")
public class PubZhxSubscribeController extends BaseController
{
    @Autowired
    private IZhxSubscribeService zhxSubscribeService;

    /**
     * 查询用户订阅列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhxSubscribe zhxSubscribe)
    {
        startPage();
        List<ZhxSubscribe> list = zhxSubscribeService.selectZhxSubscribeList(zhxSubscribe);
        return getDataTable(list);
    }

    /**
     * 导出用户订阅列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:export')")
    @Log(title = "用户订阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhxSubscribe zhxSubscribe)
    {
        List<ZhxSubscribe> list = zhxSubscribeService.selectZhxSubscribeList(zhxSubscribe);
        ExcelUtil<ZhxSubscribe> util = new ExcelUtil<ZhxSubscribe>(ZhxSubscribe.class);
        util.exportExcel(response, list, "用户订阅数据");
    }

    /**
     * 获取用户订阅详细信息（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:query')")
    @GetMapping(value = "/{subscribeId}")
    public AjaxResult getInfo(@PathVariable("subscribeId") Long subscribeId)
    {
        return success(zhxSubscribeService.selectZhxSubscribeBySubscribeId(subscribeId));
    }

    /**
     * 新增用户订阅（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:add')")
    @Log(title = "用户订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhxSubscribe zhxSubscribe)
    {
        return toAjax(zhxSubscribeService.insertZhxSubscribe(zhxSubscribe));
    }

    /**
     * 修改用户订阅（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:edit')")
    @Log(title = "用户订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhxSubscribe zhxSubscribe)
    {
        return toAjax(zhxSubscribeService.updateZhxSubscribe(zhxSubscribe));
    }

    /**
     * 删除用户订阅（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:remove')")
    @Log(title = "用户订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subscribeIds}")
    public AjaxResult remove(@PathVariable Long[] subscribeIds)
    {
        return toAjax(zhxSubscribeService.deleteZhxSubscribeBySubscribeIds(subscribeIds));
    }

    /**
     * 查询用户订阅列表
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:list')")
    @GetMapping("/listSubscribe")
    public ZhxSubscribeInfoAndTotal listSubscribe(ZhxSubscribe zhxSubscribe)
    {
        startPage();
        ZhxSubscribeListAndTotal zhxSubscribeListAndTotal = zhxSubscribeService.selectZhxSubscribeListTodo(zhxSubscribe);
        TableDataInfo tableDataInfo = getDataTable(zhxSubscribeListAndTotal.getZhxSubscribeList());

        ZhxSubscribeInfoAndTotal zhxSubscribeInfoAndTotal = new ZhxSubscribeInfoAndTotal();
        zhxSubscribeInfoAndTotal.setTableDataInfo(tableDataInfo);
        zhxSubscribeInfoAndTotal.setTotal(zhxSubscribeListAndTotal.getTotal());
        return zhxSubscribeInfoAndTotal;
    }

    /**
     * 新增用户订阅
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:add')")
    @Log(title = "用户订阅", businessType = BusinessType.INSERT)
    @PostMapping("/addSubscribe")
    public AjaxResult addSubscribe(@RequestBody ZhxSubscribe zhxSubscribe)
    {
        return toAjax(zhxSubscribeService.insertZhxSubscribeTodo(zhxSubscribe));
    }

    /**
     * 删除用户订阅
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxSubscribe:remove')")
    @Log(title = "用户订阅", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeSubscribe/{subscribeId}")
    public AjaxResult removeSubscribe(@PathVariable Long subscribeId)
    {
        return toAjax(zhxSubscribeService.deleteZhxSubscribeBySubscribeIdTodo(subscribeId));
    }

}
